package com.service.admin.impl;

import com.dao.GoodsDao;
import com.entity.Goods;
import com.service.admin.AdminGoodService;
import com.utils.SqlSessionGetter;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 管理员商品相关的服务实现类
 *
 * 
 */
@Service
public class AdminGoodServiceImpl implements AdminGoodService {

  @Override
  public int getAllGoodCount() {
    SqlSession session = SqlSessionGetter.getSqlSession();
    GoodsDao dao = session.getMapper(GoodsDao.class);
    int count = dao.selectAllGoodCount();
    session.close();
    return count;
  }

  @Override
  public List<Goods> getAllGoods(int pageSize, int pageIndex) {
    SqlSession session = SqlSessionGetter.getSqlSession();
    GoodsDao dao = session.getMapper(GoodsDao.class);
    List<Goods> goods = dao.selectAllGoods(pageIndex * pageSize, pageSize);
    session.close();
    return goods;
  }
}
